package com.san.hkhospital.controller;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.entity.Bed;
import com.san.hkhospital.entity.Employee;
import com.san.hkhospital.entity.Room;
import com.san.hkhospital.service.BedService;
import com.san.hkhospital.service.impl.BedServiceImpl;
import com.san.hkhospital.vo.BedTableVo;
import com.san.hkhospital.vo.ResultVO;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (bed)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/bed")
public class BedController {
/**
* 服务对象
*/
@Resource
private BedServiceImpl bedServiceImpl;
@Autowired
private BedService bedService;

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public Bed selectOne(Integer id) {

    return bedServiceImpl.selectByPrimaryKey(id);
}
@RequestMapping("selectBed")
public ResultVO selectBed(@RequestParam Integer sectionId,@RequestParam Integer stateId,@RequestParam Integer pageNum,@RequestParam Integer pageSize){
    PageInfo bedTableVos = bedService.selectAll(sectionId,stateId,pageNum,pageSize);
    return ResultVO.success("病床查询成功！",bedTableVos);
}

    @RequestMapping("selectBed2")
    public ResultVO selectBed2(@RequestParam Integer sectionId,@RequestParam Integer stateId){
        List<BedTableVo> bedTableVos = bedService.selectAll2(sectionId,stateId);
        return ResultVO.success("病床查询成功！",bedTableVos);
    }


    @PostMapping
    public ResultVO addBed(@RequestBody Bed bed){
    boolean flag = bedService.addBed(bed);
    if (flag){
        return ResultVO.success("病床添加成功！");
    }
    return ResultVO.failed("病床添加失败！");
}


    @RequestMapping("updateBed")
    public ResultVO updateBed(@RequestBody Bed bed){
        System.out.println(bed);
        try {
            boolean b = bedService.updateBed(bed);
            System.out.println(b);
            if (b){
                return ResultVO.success("状态修改成功！");
            }
            return ResultVO.failed("状态修改失败！");
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.failed("状态修改失败，服务器内部错误：" + e.getMessage());
        }
    }
@RequestMapping("findOneBed")
    public ResultVO findOneBed(@RequestParam Integer bedId){
    Bed bed = bedService.findOneBed(bedId);
    return ResultVO.success("查找一个病床成功！",bed);
}

}
